import hasPermi from './hasPermi'
import hasPermiNot from './hasPermiNot'
import { createPermissions } from 'az-permission'

const permissionsCaches = {
  permissions: createPermissions([]),
}

export function setCaches(permissions = [], adminPermission) {
  permissionsCaches.permissions = createPermissions(permissions, adminPermission)
}

const install = function (Vue, permissions, adminPermission) {
  setCaches(permissions, adminPermission)
  Vue.directive('hasPermi', hasPermi(permissionsCaches))
  Vue.directive('hasPermiNot', hasPermiNot(permissionsCaches))
  Vue.prototype.hasPermission = function (value) {
    return permissionsCaches.permissions.has(value)
  }
}

class AzPermission {}

AzPermission.install = install

if (window && window.Vue) {
  window.Vue.use(AzPermission)
}

export default AzPermission
